package device;
import environment.data.IEnvironmentData;
import environment.object.BaseEnvironmentObject;

import java.util.Date;


public class TemperatureSensor extends BaseDevice implements IEnvironmentData,ISensor {



    private Long lastValue;
    private Date lastDate;

    public TemperatureSensor(Long id, String name, BaseEnvironmentObject object) {
        super(id, name, object);
    }

    @Override
    public void initData() {

    }

    @Override
    public void updateData() {
        System.out.println(System.currentTimeMillis()+"| "+getEnvironmentObject().getName()+" "+getName());
        System.out.println(System.currentTimeMillis()+"| "+getEnvironmentObject().getListEnvironmentData().get(0).getValue());
        setLastDate(new Date());
        setLastValue(getEnvironmentObject().getListEnvironmentData().get(0).getValue());
    }

    @Override
    public void run() {
        for (;;){
            updateData();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public Long getLastData() {
        return lastValue;
    }

    @Override
    public Date getLastDate() {
        return lastDate;
    }

    public Long getLastValue() {
        return lastValue;
    }

    public void setLastValue(Long lastValue) {
        this.lastValue = lastValue;
    }

    public void setLastDate(Date lastDate) {
        this.lastDate = lastDate;
    }
}
